<template>
	<view>
		<view v-for='(item,index) in fileList'>
			<text @tap='downLoad(item.fileId)' style="color: #1890ff;">{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	import config from '@/common/js/config.js'
	import helper from '@/common/js/helper.js'
	let apiKey = uni.getStorageSync('apiKey') || 'api';
	let baseUrl = config.Global.baseUrl[apiKey].apiUrl;
	export default {
		props:{
			fileList:{
				type: Array,
				default(){
					return []
				}
			},
		},
		data() {
			return {
				
			}
		},
		methods: {
			/* 点击文件列表 */
			downLoad(fileId){
				//#ifdef MP
					uni.navigateTo({
						url:'../filePreview/filePreview?fileId='+ fileId
					})
					return
				//#endif
				helper.ajax({
					url: '/api/file/Download/workFlow/'+fileId,
					success: res => {
						if(res.data.code == 200){
							let url = res.data.data.url;
							let fileUrl = baseUrl + url;
							//#ifdef H5
							window.location.href = baseUrl + url;
							//#endif
							
							//#ifdef APP-PLUS
							this.downloadFile(url);
							//#endif
						}
					}
				});
			},
			
			
			/* 预览文件 */
			downloadFile(url){
				console.log(url)
				uni.downloadFile({
				  url: baseUrl+url,
				  success: function (res) {
					  console.log(res)
				    var filePath = res.tempFilePath;
					uni.openDocument({
					  filePath: filePath,
					  fileType: 'docx',
					  success: function (res) {
					    console.log(res)
					  }
					});
				  }
				});
			},
		}
	}
</script>

<style>

</style>
